
Page({
  data:{
    isTFShow:false,
    //apppid:'3000000048925312'
    // name: '',
    // appUrl: 'https://m.duanqu.com?_ariver_appid=3000000048925193&_mp_code=tb&transition=present',
    // startTime: '',
    // endTime: '',
    // appId: '3000000048925193',
    // targetEntityList: [],     //投放商品列表 可传入[]
    // go2Table:false,
    // myCallBack(){},
    // myCallBackWithSetData:null, // 使用进行setData的callback
    // myBackCallback(){},
    // myBackCallbackWithSetData:null,  // 注意this的指向(绑定this)
  },
  onLoad(query) {
     
    // let start = "2021-10-16 15:00:00"
    // let end = "2021-10-16 15:10:00"

    //console.log("开始时间",new Date(start).getTime(),"结束时间",new Date(end).getTime());

    // 页面加载
    //console.info(`Page onLoad with query: ${JSON.stringify(query)}`);

    this.getAuth();

    // 656979931255,651311392532

  },

  

  //input change
  inputChange(e){

    if(e.currentTarget.dataset.name == 'name'){
      this.setData({
        name:e.detail.value
      })
    }else if(e.currentTarget.dataset.name == 'date'){
      this.setData({
        startTime:new Date(e.detail.value[0]).getTime(),
        endTime:new Date(e.detail.value[1]).getTime()
      })
    }else{
      if(e.detail.value.indexOf(',') == -1){
        let i=[];
        i.push(parseInt(e.detail.value))
        this.setData({
          targetEntityList:i
        })
      }else{
        let arr=e.detail.value.split(',');
        let parseIntArr=[];
        for(let i in arr){
          parseIntArr.push(parseInt(arr[i]))
        }
        this.setData({
          targetEntityList:parseIntArr
        })
      }
    }

    //console.log("开始时间：",this.data.startTime,"结束时间：",this.data.endTime,"投放名称：",this.data.name,"商品组id：",this.data.targetEntityList)
  },

  //新建投放
  startZDTF(){

    getApp().name = this.data.name
    getApp().startTime = this.data.startTime
    getApp().endTime = this.data.endTime
    getApp().targetEntityList = this.data.targetEntityList


    // my.navigateTo({
    //   url: `../list/list`
    // })

    if(this.data.name && this.data.startTime && this.data.endTime && this.data.targetEntityList){
      my.navigateTo({ url: '../list/list' })
    }else{
      my.alert({content:'投放信息填写不完整！'})
    }

   

    return;
    
    this.setData({
      isTFShow:true
    });
    
    this.cb = this.cb.bind(this);
    this.backCb = this.backCb.bind(this);

    this.setData({
      myCallBackWithSetData: this.cb.bind(this),
      myBackCallbackWithSetData: this.backCb.bind(this)
    })

  },

  //查看投放记录
  toufangJL(){
    my.qn.navigateToWebPage({
      url: "https://market.m.taobao.com/app/taefed/shopping-delivery-wapp/index.html#/putin?appId=3000000048925193",
      success: res => {
      },
      fail: res => {
      }
    })
  },

  //装修教程
  zxJC(){
    my.qn.navigateToWebPage({
      url: "https://www.yuque.com/docs/share/f1b393ab-7d33-4af5-9910-0c13502b875a?#",
      success: res => {
      },
      fail: res => {
      }
    })
  },

  getAuth() {//获取用户授权
    my.authorize({
      scopes: '*',
      success: (res) => {
        my.getAuthUserInfo({
          success: (userInfo) => {
            //调用后端接口
            let option ={
              userNick:userInfo.nickName,
              avatar:userInfo.avatar
            }
            getApp().cloud.function.invoke('business',option,"login").then(res => {
              // my.alert({
              //   content:JSON.stringify(res)
              // })
              if(res.code == 200){
                my.alert({content:'授权成功！'})
              }
            })
          },
          fail: (er) => {
            my.alert({ title: '获取失败', content: JSON.stringify(er) });
          }
        });
      },
      fail: (e) => {
        my.alert({ title: '授权失败', content: JSON.stringify(e) });
      }
    });
  
  },

  tf(){
      // 拿到实例化后的小程序id
      //my.navigateTo({ url: 'plugin://myPlugin1/orightindex-page' });

      // let appid="3000000028703214";

      //https://market.m.taobao.com/app/taefed/shopping-delivery-wapp/index.html#/putin?mainKey=form&appId=3000000005074923


      // my.alert({content:getApp().APPID})

      //let apppid = "3000000029413603"
      
      let link = `https://market.m.taobao.com/app/taefed/shopping-delivery-wapp/index.html#/putin?mainKey=form&appId=3000000048925193`;

       my.qn.naviateToWebPage({
        url: link,
        success: res => {

        },
        fail: res => {

        }
      })
      
    },
  onReady() {
    // 页面加载完成
  },
  onShow() {
    // 页面显示
  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  onShareAppMessage() {
    // 返回自定义分享信息
    return {
      title: 'My App',
      desc: 'My App description',
      path: 'pages/index/index',
    };
  },
});
